﻿using Application.Common.Interface;
using Microsoft.AspNetCore.Mvc;

namespace Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly ISiteMapRepository siteMapRepository;

        public HomeController(ILogger<HomeController> logger, ISiteMapRepository siteMapRepository)
        {
            _logger = logger;
            this.siteMapRepository = siteMapRepository;
        }

        public async Task<IActionResult> Index(string query)
        {
            ViewBag.query = query;
            if (string.IsNullOrEmpty(query))
            {
                var model = await siteMapRepository.GetAllAsync();
                return View(model);
            }
            else
            {
                var model = await siteMapRepository.GetSearchByIDDomain(query);
                return View(model);
            }
        }
    }
}